﻿using Prompts.Prompting.ViewModels;
using Prompts.ReportCatalog.Model;
using Prompts.ReportCatalog.ViewModels;
using Prompts.ReportCatalog.ViewModels.Implementation;
using Prompts.ReportCatalog.Views;

namespace Prompts
{
    public class ReportCatalogContainer
    {
        public IPromptsViewModel PromptsViewModel { get; set; }

        public ReportCatalogControl Create()
        {
            return CreateReportCatalogControl(InjectReportCatalogViewModel());
        }

        protected virtual ReportCatalogControl CreateReportCatalogControl(
            IReportCatalogViewModel reportCatalogItemViewModel)
        {
            return new ReportCatalogControl(reportCatalogItemViewModel);
        }

        public IReportCatalogViewModel InjectReportCatalogViewModel()
        {
            return CreateReportCatalogViewModel(CreateReportCatalogService());
        }

        protected virtual IReportCatalogViewModel CreateReportCatalogViewModel(IReportCatalogViewModelService reportCatalogViewModelService)
        {
            return new ReportCatalogViewModel(reportCatalogViewModelService);
        }

        private IReportCatalogViewModelService CreateReportCatalogService()
        {
            return new ReportCatalogViewModelService(
                CreateReportCatalogServiceClient()
                , CreateReportCatalogBuilder());
        }

        private ICatalogItemViewModelBuilder CreateReportCatalogBuilder()
        {
            return new CatalogItemViewModelBuilder(PromptsViewModel);
        }

        private static IReportCatalogServiceClient CreateReportCatalogServiceClient()
        {
            return ServiceInjector.Inject<IReportCatalogServiceClient>();
        }
    }
}
